/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.swan.plugin;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;

/**
 * Goal which generate pojo file from db
 */
@Mojo(name = "help", defaultPhase = LifecyclePhase.NONE)
public class HelpMojo extends AbstractMojo {
    public static final String RESET = "\033[0m";
    public static final String BOLD_BLUE = "\033[1:34m";
    public static final String BOLD = "\033[1m";
    @Parameter(defaultValue = "${project.build.directory}/generated-sources/robot/java", property = "outputDir", required = true)
    private File outputDirectory;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        StringBuilder sb = new StringBuilder();
        sb.append("version 1.0.0.001\n");
        sb.append("Maven Plugin that executes code generate\n");
        sb.append("This plugin has 5 goals:\n");
        sb.append(BOLD_BLUE+"pojo:"+RESET+"\n");
        sb.append("  Used to generate source code from data file(Json format) \n");
        sb.append("  There are three parameter optional. \n");
        sb.append(BOLD+"  dataPath"+RESET+": Default path is ${basedir}/template  \n");
        sb.append(BOLD+"  templatePath"+RESET+": Default path is ${basedir} \n");
        sb.append(BOLD+"  outputPath"+RESET+": Default path is ${project.build.directory}/generated-sources/robot/java \n");
        sb.append(BOLD_BLUE+"config:"+RESET+"\n");
        sb.append("  Generate config file and readme.md \n");
        sb.append(BOLD_BLUE+"db:"+RESET+"\n");
        sb.append("  Generate config file used by goal:[db].\n");
        sb.append("  Use to generate pojo json file from db, there are seven parameter need to set.\n");
        sb.append(BOLD+"  dataPath"+RESET+": the folder that save the data json file, default is ${project.basedir}/template\n");
        sb.append(BOLD+"  driver"+RESET+": The JDBC driver used to connect to database.\n");
        sb.append(BOLD+"  url"+RESET+": JDBC url used to connect to database.\n");
        sb.append(BOLD+"  user"+RESET+": User name of database used to connect to database.\n");
        sb.append(BOLD+"  password"+RESET+": Password of user in database used to connect to database.\n");
        sb.append(BOLD+"  database"+RESET+": Database name tat will be scanned, all table or view will be used to create data json file..\n");
        sb.append(BOLD+"  packageName"+RESET+": the default packageName of the data.\n");
        sb.append("\n");
        sb.append("  If file exists will be ignored.\n");
        sb.append("  You need to add dependency into this plugin that include the JDBC driver you set in the parameter.\n");
        sb.append("  You can use _default_config.json to define some field with default value.\n");
        sb.append(BOLD_BLUE+"clean"+RESET+"\n");
        sb.append("  Used to clear the java source file that generated by this plugin.\n");
        sb.append(BOLD_BLUE+"help"+RESET+"\n");
        sb.append("  Used to display help message.");
        getLog().info(sb);
    }

}
